package com.server.llh.llhserverwork.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.bean.ServerInfoBean;

import java.util.List;

/**
 * Created by ZTF on 2017-06-14.
 */

public class ServerInfoAdapter extends BaseAdapter {
    Context context;
    List<ServerInfoBean.DataBean> accountList;
    public  ServerInfoAdapter(Context context,List<ServerInfoBean.DataBean> accountList){
        this.context=context;
        this.accountList=accountList;
    }

    @Override
    public int getCount() {
        if (accountList==null&&accountList.size()==0){
            return  0;
        }
        return accountList.size();
    }

    @Override
    public Object getItem(int position) {
        return accountList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VierHolder h = new VierHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.llh_server_info_item, null);
            h.server_name = (TextView) convertView.findViewById(R.id.server_name);
            h.server_age = (TextView) convertView.findViewById(R.id.server_age);
            h.server_sex = (TextView) convertView.findViewById(R.id.server_sex);
            convertView.setTag(h);
        } else {
            h = (VierHolder) convertView.getTag();
        }
        ServerInfoBean.DataBean  serverInfo= accountList.get(position);
        h.server_name.setText("姓名："+serverInfo.getUserName());
        h.server_age.setText("年龄："+serverInfo.getUserAge());
        if (serverInfo.getUserSex()==1){
            h.server_sex.setText("性别：女");
        }else{
            h.server_sex.setText("性别：男");
        }
        return convertView;
    }

    class VierHolder {
        TextView server_name,server_age,server_sex;
    }

}
